﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CrystalDecisions.Enterprise;
using CrystalDecisions.Enterprise.Dest;

namespace BO.Management
{
    public class SmtpProvider : BaseSystemObjectProvider<DestinationPlugin>
    {
 
        /// <summary>
        /// Default constructor required the LogonProvider used to connect to BO Cms
        /// </summary>
        /// <param name="logonProvider"></param>
        public SmtpProvider(LogonProvider logonProvider)
            : base(logonProvider)
        {
           
        }

        public override ObjectKind Kind
        {
            get { return ObjectKind.Smtp; }
        }

        public DestinationPlugin GetDestinationPlugin()
        {
            String smtpQry = "Select SI_DEST_SCHEDULEOPTIONS, SI_PROGID From CI_SYSTEMOBJECTS Where SI_PARENTID=29 and SI_NAME='CrystalEnterprise.SMTP'";
            using (CrystalDecisions.Enterprise.InfoObjects results = this.InfoStore.Query(smtpQry))
            {
                if (results != null && results.Count > 0)
                {
                    InfoObject result= results[1];
                    DestinationPlugin destPlugin = new DestinationPlugin(result.PluginInterface);
                    return destPlugin;
                }
                else
                {
                    return null;
                }
            }


        }
    }
}
